//
//  AppDelegate.m
//  Bettle
//
//  Created by panhongliu on 2016/12/30.
//  Copyright © 2016年 . All righ杨东旭ts reserved.
//
#import "ChatViewController.h"
#import <Hyphenate_CN/EMSDKFull.h>
#import "Networking.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "CYLmanager.h"
#import "FriendListViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"groupId" conversationType:EMConversationTypeGroupChat];
    
    
    
    //AppKey:注册的AppKey，详细见下面注释。
    //apnsCertName:推送证书名（不需要加后缀），详细见下面注释。
    EMOptions *options = [EMOptions optionsWithAppkey:@"1189170115178443#jiakechong"];
   // options.apnsCertName = @"istore_dev";
    EMError *error = [[EMClient sharedClient] initializeSDKWithOptions:options];
    if (!error) {
        NSLog(@"初始化成功");
    }
    EMError *error1 = [[EMClient sharedClient] registerWithUsername:@"8002" password:@"111111"];
    if (error1==nil) {
        NSLog(@"注册成功");
    }
    EMError *error2 = [[EMClient sharedClient] loginWithUsername:@"8002" password:@"111111"];
    if (!error2) {
        NSLog(@"登录成功");
    }
    //环信ID:@"8001"
    //聊天类型:EMConversationTypeChat
   //EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"8001" conversationType:EMConversationTypeChat];
    
    // 设置主窗口,并设置根控制器
    self.window = [[UIWindow alloc]init];
    self.window.frame = [UIScreen mainScreen].bounds;

    [[NetworkManger shareManager]setBaseUrl:@"http://59.110.71.186:8080"];
    [[NetworkManger shareManager]setErrorOrRightCode:@"code"];
    
    
    ChatViewController *ChatVC = [[ChatViewController alloc]initWithConversationChatter:@"8001" conversationType:EMConversationTypeChat];
    EMError *error3 = nil;
    EMGroupOptions *setting = [[EMGroupOptions alloc] init];
    setting.maxUsersCount = 500;
    setting.style = EMGroupStylePublicOpenJoin;// 创建不同类型的群组，这里需要才传入不同的类型
    EMGroup *group = [[EMClient sharedClient].groupManager createGroupWithSubject:@"群组名称" description:@"群组描述" invitees:@[@"8001",@"8002"] message:@"邀请您加入群组" setting:setting error:&error3];
    if(!error3){
        NSLog(@"创建成功 -- %@",group);
    }

    
    
    UINavigationController *chatav = [[UINavigationController alloc]initWithRootViewController:ChatVC];
    
     FriendListViewController *feVC = [[FriendListViewController alloc]initWithConversationChatter:@"groupId" conversationType:EMConversationTypeGroupChat];
    
    LoginViewController *LoginVC = [[LoginViewController alloc]init];
    UINavigationController *loginNAV = [[UINavigationController alloc]initWithRootViewController:LoginVC];
    
    UINavigationController *FeNAV = [[UINavigationController alloc]initWithRootViewController:feVC];
    [self.window setRootViewController:loginNAV];
    // [self.window setRootViewController:chatav];
    //[self.window setRootViewController:FeNAV];

    [self.window makeKeyAndVisible];
    return YES;
}


+(AppDelegate *)shareInstance{
   
    return (AppDelegate *)[UIApplication sharedApplication].delegate;
}
-(void)goinloginviewcontroller{
    CYLmanager *tabBarControllerConfig = [[CYLmanager alloc] init];
    [self.window setRootViewController:tabBarControllerConfig.tabBarController];

}
- (void)applicationWillResignActive:(UIApplication *)application {

}


- (void)applicationDidEnterBackground:(UIApplication *)application {
   //app进入后台
    [[EMClient sharedClient] applicationDidEnterBackground:application];

}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    //app将要从后返回
    [[EMClient sharedClient] applicationWillEnterForeground:application];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
